package com.hontech.bv.conn.serial

import com.hontech.bv.codec.decodeUint16
import com.hontech.bv.codec.encodeUint16

class Uint16 (var value: Int = 0) : SerialType {

    override fun size(): Int {
        return 2
    }

    override fun encode(buf: ByteArray, offset: Int) {
        encodeUint16(buf, offset, value)
    }

    override fun decode(buf: ByteArray, offset: Int) {
        value = decodeUint16(buf, offset)
    }

    fun signalValue(): Int {
        if ((value and 0x8000) != 0) {
            return -(0x10000 - value)
        }
        return value
    }
}

